package com.hake.manager.system.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.hake.core.exception.AppException;
import com.hake.core.support.HttpCode;
import com.hake.core.support.web.BaseController;
import com.hake.manager.system.entity.User;
import com.hake.manager.system.service.UserService;

@RestController
@RequestMapping("user")
public class UserController extends BaseController {

	@Autowired
	private UserService service ;
	
	
	@RequestMapping(value="/read/list")
	public Object get(HttpServletRequest request, ModelMap modelMap) {
		User selectByPrimaryKey = null;
		PageInfo<User> selectByPageInfo = null;
		/*User covert = RequestParamUtil.covert(User.class, request);
		List<User> covert2 = Request2ListUtil.covert(User.class, request) ;
		for (User user : covert2) {
			System.out.println(user);
		}
		System.out.println(covert);
		
		String applicationResource = WebUtil.getApplicationResource("HTTPCODE_400", request) ;
		System.out.println(applicationResource);
		
		System.out.println(WebUtil.getHost(request));
		System.out.println(WebUtil.getParameterMap(request));
		System.out.println(WebUtil.getCookieValue(request, "JSESSIONID", null));*/
		
		try {
			selectByPageInfo = this.service.selectByPageInfo(null) ;
			for (User user : selectByPageInfo.getList()) {
				System.out.println(JSON.toJSON(user));
			}
			//selectByPrimaryKey = this.service.selectByPrimaryKey(633);
		} catch (AppException e) {
			System.out.println(e.getLocalizedMessage());
			return setModelMap(modelMap, HttpCode.INTERNAL_SERVER_ERROR, selectByPageInfo);
		}
		return setModelMap(modelMap, HttpCode.OK, selectByPrimaryKey);
	}
	
	
}

